<?php
	include_once dirname(dirname(dirname(__FILE__))).'/inc/bootConfig.php';
	include_once '../checkLogin.php';
	
	$pid = getRequest('id');  //产品ID
	$dir = "../../zjx/Runtime/Cache/selectModel/";
	if(isset($_POST['add_attr'])){
		$upd['a_pid'] = $pid;
		$upd['a_name'] = getRequest('name');
		$upd['a_info'] = addslashes(sy2dy($_REQUEST['attrcon']));
		$upd['a_grade'] = getRequest('grade');
		$upd['a_user'] = $_SESSION['username'];
		$upd['a_time'] = date('Y-m-d H:i:s');
		$tablename = 'zjx_proattr';
		if(Module_Edit::insert($tablename,$upd)){
			Cache_Filecache::delFileCache($dir);
			jstop('添加成功');
		}
		jstop('系统繁忙，请重试');
	}
	if(isset($_POST['edit_attr'])){
		$aid = getRequest('aid');
		$upd['a_name'] = getRequest('name');
		$upd['a_info'] = addslashes(sy2dy($_REQUEST['attcon'.$aid]));
		$upd['a_grade'] = getRequest('grade');
		$upd['a_user'] = $_SESSION['username'];
		$upd['a_time'] = date('Y-m-d H:i:s');
		$tablename = 'zjx_proattr';	
		if(Module_Edit::update($tablename,$upd,'a_id='.$aid)){
			Cache_Filecache::delFileCache($dir);
			jstop('修改成功');
		}
		jstop('系统繁忙，请重试');	
	}
	$edit = getRequest('edit');
	if(!empty($edit) && $edit=='del'){
		$aid = getRequest('aid');
		Module_Edit::delete('zjx_proattr','a_id='.$aid);	
		Cache_Filecache::delFileCache($dir);
	}
	$productinfo = Module_Select::getProductInfoById($pid);
	$proattr = Module_Select::getAllAttrByPid($pid);
?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>产品属性操作</title>
<link rel="stylesheet" type='text/css' href='../Public/static/css/admincp/admincp.css'>
<link rel="stylesheet" type="text/css" href="/admin/Public/css/main.css" />
</head>
<body>
<div id="cpcontainer" class="container">
	<div class="floattop">
		<div class="itemtitle">
			<h3>已发布产品管理</h3>
		</div>
	</div>
</div>
<table id="tips" class="tb tb2 ">
	<tbody>
		<tr>
			<th class="partition" colspan='2'>技巧提示</th>
		</tr>
		<tr>
			<td class="tipsblock" colspan='2'>
			<ul id="tipslis">
				<li>点击相应的属性可查看其内容，并且可以修改</li>
				<li>点击添加即可添加相应属性，其中显示顺序数字越小越靠前</li>
				<li>为了不显示前台显示，每个产品相关属性最好不要越过 4 个</li>
			</ul>
			</td>
		</tr>
	</tbody>
</table>
<div class="node-products node-promoted node-full clearfix" style="width:90%" id="node-58">
    <div class="content clearfix">
    	<p align="center">
    		<img alt="" width="200" src="/www/static/images/product/<?php echo $productinfo['p_image'] ?>">
    	</p>
    	<div class="product-content-tab">
    	<ul>
        	<li class="active">基本信息</li>
        <?php 
        	if(is_array($proattr) && count($proattr)>0){
				foreach($proattr as $v){
        ?>
           	 <li class=""><?php echo $v['a_name']?></li>
        <?php
        		}
			}
        ?>
			<li id='addatt' class="">添加</li>
        </ul>
   		 </div>
   		 <div class="product-content-container">
    		<div class="contents active">
		        <?php echo $productinfo['p_info']?>
	        </div>
	    <?php 
        	if(is_array($proattr) && count($proattr)>0){
				foreach($proattr as $v){
        ?>
	           	<div class="contents">
					<span>
						<?php echo $v['a_info']?>
						<br><br>
						<input type='button' class='btn editatt' value='编辑'/>
						<input type='button' class='btn delatt' pid='<?php echo $v['a_id']?>' value='删除'/>
					</span>
					<form action='' method='post' style="display:none">
						<input type='hidden' name='aid' value="<?php echo $v['a_id']?>"/>
						<table border=0 width='100%' cellspacing='10' cellpadding='10' style="background:#CCE8CF">
							<tr bgcolor='#fefefe'>
								<td align='right' width="100px">名称：</td>
								<td><input type='text' name='name' value='<?php echo $v['a_name']?>'/></td>
							</tr>
							<tr bgcolor='#fefefe'>
								<td align='right' width="100px">显示顺序：</td>
								<td><input type='text' name='grade' value='<?php echo $v['a_grade']?>'/></td>
							</tr>
							<tr bgcolor='#fefefe'>
								<td align='right' width="100px">内容：</td>
								<td>
									<INPUT id=content style="DISPLAY: none" type=hidden name="attcon<?php echo $v['a_id']?>" value="<?php echo htmlspecialchars($v['a_info'])?>">
									<INPUT id=content___Config style="DISPLAY: none" type=hidden> 
									<IFRAME id=content___Frame src="../Public/static/FCK/editor/fckeditor.html?InstanceName=attcon<?php echo $v['a_id']?>&Toolbar=Default" frameBorder=0 width=70% scrolling=no height=400> 
									</IFRAME>
								</td>
							</tr>
							<tr bgcolor='#fefefe'>
								<td align='right' width="100px"></td>
								<td>
									<input type='submit' class='btn' name='edit_attr' value='提交'/>
									<input type='button' name='' class='btn back' value='取消'/>
								</td>
							</tr>
						</table>
					</form>
		        </div>
        <?php
        		}
			}
        ?>
	        <div class="contents">
				<form action='' method='post'>
					<table border=0 width='100%' cellspacing='10' cellpadding='10' style="background:#CCE8CF">
						<tr bgcolor='#fefefe'>
							<td align='right' width="100px">名称：</td>
							<td><input type='text' name='name' value=''/></td>
						</tr>
						<tr bgcolor='#fefefe'>
							<td align='right' width="100px">显示顺序：</td>
							<td><input type='text' name='grade' value=''/></td>
						</tr>
						<tr bgcolor='#fefefe'>
							<td align='right' width="100px">内容：</td>
							<td>
								<INPUT id=content style="DISPLAY: none" type=hidden name="attrcon" value="<? echo $modcon['c_content'] ?>">
								<INPUT id=content___Config style="DISPLAY: none" type=hidden> 
								<IFRAME id=content___Frame src="../Public/static/FCK/editor/fckeditor.html?InstanceName=attrcon&Toolbar=Default" frameBorder=0 width=70% scrolling=no height=400> 
								</IFRAME>
							</td>
						</tr>
						<tr bgcolor='#fefefe'>
							<td align='right' width="100px"></td>
							<td>
								<input type='submit' class='btn' name='add_attr' value='提交'/>
								<input type='submit' name='' class='btn' onclick="history.back();" value='返回'/>
							</td>
						</tr>
					</table>
				</form>
		    </div>
    	</div>
  	    <div class="documentation">
    	</div>
  </div>
</div>
<script type="text/javascript" src="/www/static/js/jquery.js"></script>
<script type="text/javascript">
	jQuery(function() {
		jQuery(".product-content-tab>ul>li").click(function() {
					jQuery(".product-content-tab>ul>li").removeClass("active");
					jQuery(this).addClass("active");
					jQuery(".product-content-container>.contents").removeClass("active");
					jQuery(".product-content-container>.contents").eq(jQuery(".product-content-tab>ul>li").index(jQuery(this))).addClass("active");
				});
	});
	$('#addatt').click(function(){
		if($(this).index()>=4){
			alert('您的属性已经有4个，继续添加将会影响前台显示')
		}
	})
	$('.editatt').click(function(){
		$(this).parents('span').hide();
		$(this).parents('div.contents').children('form').show();
	})
	$('.back').click(function(){
		$(this).parents('div.contents').children('span').show();
		$(this).parents('div.contents').children('form').hide();
	})
	$('.delatt').click(function(){
		if(confirm('确定删除吗？')){
			location.href = '?id=<?php echo $pid?>&aid='+$(this).attr('pid')+'&edit=del'
		}
	})
</script>

</body>
</html>